<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>
<script>
    // 想要获取一个最接近 1280x720 的相机分辨率
    var constraints = { audio: true, video: { width: 320, height: 480 } };
    navigator.mediaDevices.getUserMedia(constraints)
        .then(function(mediaStream) {
            var video = document.querySelector('video');
            video.srcObject = mediaStream;
            video.onloadedmetadata = function(e) {
                video.play();
            };
        })
        .catch(function(err) { console.log(err.name + ": " + err.message); });

</script>
<body>
<video width="320" height="480" controls>

    你的浏览器不支持 video 标签。
</video>
</body>
</html>
